<?php
  class UserAction extends Action {
    public function index() {
      $m = M('User');
      $arr = $m->select();
      $this->assign('data', $arr);
      $this->display();
    }

    public function del() {
      $m = M('User');
      $id = $_GET['id'];
      $count = $m->delete($id);
      if($count > 0)
      {
        $this->success("数据删除成功！");
      }
      else
      {
        $this->error("数据删除失败！");
      }
    }
    
    /*
    **显示修改页面
    */
    public function modify() {
      $m = M('User');
      $id = $_GET['id'];
      $arr=$m->find($id);
      $this->assign('data',$arr);
      $this->display();
    }
    public function update() {
      $m = M('User');
      $data['id'] = $_POST['id'];
      $data['username'] = $_POST['username'];
      $data['sex'] = $_POST['sex'];
      $count = $m->save($data);
      if($count > 0)
      {
        $this->success("数据更改成功！", "index");
      }
      else
      {
        $this->error("数据更改失败！");
      }
    }

    public function add() {
    	$this->display();
    }
    public function create() {
    	$m = M('User');
    	$m->username=$_POST['username'];
    	$m->sex=$_POST['sex'];
    	$count = $m->add();
    	if($count > 0)
      {
        $this->success("用户添加成功！", "index");
      }
      else
      {
        $this->error("用户添加失败！");
      }
    }
  }
?>